26. Solution: SpotBugs
Solution: SpotBugs
ND079 JPND C3 L2 A21 Solution Spotbugs
Add SpotBugs to Reporting
To add SpotBugs to your site
phase, add the following to the top level of your <project>
element.
<reporting>
<plugins>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>4.1.4</version>
</plugin>
</plugins>
</reporting>
Run Maven Site
Run the site phase with the command:
mvn site
Check the Report
Open the target/site/spotbugs.html
. You should see a High Priority error for HE_EQUALS_USE_HASHCODE. Clicking on this error will take you to a page describing the message in more detail.
Fixing the Error
To fix the error, you will need to implement the hashCode
method in this class, because it is bad practice to overried equals
and not hashCode
. Once you fix the problem, you should be able to rerun the mvn site
command and see the error removed from the report.